package com.yunkaweilai.android.view.dialog.guadan;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.github.lazylibrary.util.StringUtils;
import com.yunkaweilai.android.R;
import com.yunkaweilai.android.constants.Api;
import com.yunkaweilai.android.interfaces.MyDialogInterface;
import com.yunkaweilai.android.net.HttpRequest;
import com.yunkaweilai.android.net.PostProcess;
import com.yunkaweilai.android.utils.Utils;
import com.yunkaweilai.android.view.MyToast;

/**
 * 挂单备注
 * Created by Administrator on 2017/6/27.
 */

public class GuadanDelRemarkDialog1 extends Dialog {
    private String group_id;
    private String gid;
    private String typeName;

    private ImageView idImgClose;
    private String type;
    private TextView idEdtTypeName;
    private EditText idEdtRemark;
    private TextView idTvType;
    private TextView idTvRigth;
    private MyDialogInterface myDialogInterface;

    public GuadanDelRemarkDialog1(@NonNull Context context, String gid, String typeName, String group_id, MyDialogInterface myDialogInterface1) {
        super(context,R.style.dialog);
        this.gid = gid;
        this.typeName = typeName;
        myDialogInterface = myDialogInterface1;
        this.group_id = group_id;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_guadan_del_remark);
        idTvRigth = (TextView) findViewById(R.id.id_tv_right);
        idEdtRemark = ((EditText) findViewById(R.id.id_edt_remark));
        idImgClose = ((ImageView) findViewById(R.id.id_img_close));
        idTvType = ((TextView) findViewById(R.id.id_tv_max_type));
        idTvType.setText(typeName);
        initClick();

    }

    private void initClick() {
        idImgClose.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
        idTvRigth.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (StringUtils.isEmpty(idEdtRemark.getText().toString())){
                    MyToast.showShortToast(getContext(),"备注不能为空");
                }else{
                    initHttp();
                }
            }
        });
    }

    private void initHttp() {
        HttpRequest.postUrl(Api.CANCLE_GUADAN)
                .addParams("GuadanRemark",idEdtRemark.getText().toString())
                .addParams("gid",gid)
                .addParams("group_id",group_id)
                .execute(new PostProcess.StringCallBack() {
                    @Override
                    public void onResponse(String json) {
                        boolean checkCode = Utils.checkCode(getContext(), json);
                        if (checkCode){
                            MyToast.showShortToast(getContext(),"操作成功");
                            myDialogInterface.RightClick();
                            dismiss();
                        }
                    }
                    @Override
                    public void onError(Exception e) {

                    }
                });
    }
}